home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Leser 15 / Amiga Plus Leser CD 15.iso / Tools / Development / MosaicSRC / libwww2 / SGML.h < prev    next >
Encoding:
C/C++ Source or Header  |  2002-03-13  |  5.7 KB  |  181 lines

  1. /*                     /Net/dxcern/userd/timbl/hypertext/WWW/Library/Implementation/SGML.html
  2.                                SGML AND STRUCTURED STREAMS
  3.                                              
  4.    The SGML parser is a state machine. It is called for every
  5.    character of the input stream. The DTD data structure contains
  6.    pointers to functions which are called to implement the actual
  7.    effect of the text read. When these functions are called, the
  8.    attribute structures pointed to by the DTD are valid, and the
  9.    function is passed a pointer to the curent tag structure, and an
  10.    "element stack" which represents the state of nesting within SGML
  11.    elements.
  12.    
  13.    The following aspects are from Dan Connolly's suggestions: Binary
  14.    search, Strcutured object scheme basically, SGML content enum type.
  15.    
  16.    (c) Copyright CERN 1991 - See Copyright.html
  17.    
  18.  */
  19. #ifndef SGML_H
  20. #define SGML_H
  21.  
  22. #include "HTUtils.h"
  23. #include "HTStream.h"
  24.  
  25. /*
  26.  
  27. SGML content types
  28.  
  29.  */
  30. typedef enum _SGMLContent{
  31.   SGML_EMPTY,    /* no content */
  32.   SGML_LITTERAL, /* character data. Recognised excat close tag only. litteral
  33.                     Old www server compatibility only! Not SGML */
  34.   SGML_CDATA,    /* character data. recognize </ only */
  35.   SGML_RCDATA,   /* replaceable character data. recognize </ and &ref; */
  36.   SGML_MIXED,    /* elements and parsed character data. recognize all markup */
  37.   SGML_ELEMENT   /* any data found will be returned as an error*/
  38.   } SGMLContent;
  39.  
  40.  
  41. typedef struct {
  42.     char *      name;           /* The (constant) name of the attribute */
  43.                                 /* Could put type info in here */
  44. } attr;
  45.  
  46.  
  47. /*              A tag structure describes an SGML element.
  48. **              -----------------------------------------
  49. **
  50. **
  51. **      name            is the string which comes after the tag opener "<".
  52. **
  53. **      attributes      points to a zero-terminated array
  54. **                      of attribute names.
  55. **
  56. **      litteral        determines how the SGML engine parses the charaters
  57. **                      within the element. If set, tag openers are ignored
  58. **                      except for that which opens a matching closing tag.
  59. **
  60. */
  61. typedef struct _tag HTTag;
  62. struct _tag{
  63.     char *      name;                   /* The name of the tag */
  64.     attr *      attributes;             /* The list of acceptable attributes */
  65.     int         number_of_attributes;   /* Number of possible attributes */
  66.     SGMLContent contents;               /* End only on end tag @@ */
  67. };
  68.  
  69.  
  70.  
  71.  
  72. /*              DTD Information
  73. **              ---------------
  74. **
  75. ** Not the whole DTD, but all this parser usues of it.
  76. */
  77. typedef struct {
  78.     HTTag *             tags;           /* Must be in strcmp order by name */
  79.     int                 number_of_tags;
  80.     CONST char **       entity_names;   /* Must be in strcmp order by name */
  81.     int                 number_of_entities;
  82. } SGML_dtd;
  83.  
  84.  
  85. /*      SGML context passed to parsers
  86. */
  87. typedef struct _HTSGMLContext *HTSGMLContext;   /* Hidden */
  88.  
  89.  
  90. /*__________________________________________________________________________
  91. */
  92. /*              Structured Object definition
  93. **
  94. **      A structured object is something which can reasonably be
  95. **      represented in SGML.  I'll rephrase that.  A structured
  96. **      object is am ordered tree-structured arrangement of data
  97. **      which is representable as text.
  98. **
  99. **      The SGML parer outputs to a Structured object.
  100. **      A Structured object can output its contents
  101. **      to another Structured Object.
  102. **      It's a kind of typed stream.  The architecure
  103. **      is largely Dan Conolly's.
  104. **      Elements and entities are passed to the sob by number, implying
  105. **      a knowledge of the DTD.
  106. **      Knowledge of the SGML syntax is not here, though.
  107. **
  108. **      Superclass: HTStream
  109. */
  110.  
  111.  
  112. /*      The creation methods will vary on the type of Structured Object.
  113. **      Maybe the callerData is enough info to pass along.
  114. */
  115.  
  116. typedef struct _HTStructured HTStructured;
  117.  
  118. typedef struct _HTStructuredClass{
  119.  
  120.         char*  name;                            /* Just for diagnostics */
  121.  
  122.         void (*free) PARAMS((
  123.                 HTStructured*   me));
  124.  
  125.         void (*end_document) PARAMS((
  126.                 HTStructured*   me));
  127.                 
  128.         void (*handle_interrupt) PARAMS((
  129.                 HTStructured*   me));
  130.                 
  131.         void (*put_character) PARAMS((
  132.                 HTStructured*   me,
  133.                 char            ch));
  134.                                 
  135.         void (*put_string) PARAMS((
  136.                 HTStructured*   me,
  137.                 CONST char *    str));
  138.                 
  139.         void (*write) PARAMS((
  140.                 HTStructured*   me,
  141.                 CONST char *    str,
  142.                 int             len));
  143.                 
  144.         void (*start_element) PARAMS((
  145.                 HTStructured*   me,
  146.                 int             element_number,
  147.                 CONST BOOL*             attribute_present,
  148.                 CONST char**            attribute_value));
  149.                 
  150.         void (*end_element) PARAMS((
  151.                 HTStructured*   me,
  152.                 int             element_number));
  153.  
  154.         void (*put_entity) PARAMS((
  155.                 HTStructured*   me,
  156.                 int             entity_number));
  157.                 
  158. }HTStructuredClass;
  159.  
  160.  
  161.  
  162. /*      Create an SGML parser
  163. **
  164. ** On entry,
  165. **      dtd             must point to a DTD structure as defined above
  166. **      callbacks       must point to user routines.
  167. **      callData        is returned in callbacks transparently.
  168. ** On exit,
  169. **              The default tag starter has been processed.
  170. */
  171.  
  172.  
  173. extern HTStream* SGML_new PARAMS((
  174.         CONST SGML_dtd *                dtd,
  175.         HTStructured *          target));
  176.  
  177. extern CONST HTStreamClass SGMLParser;
  178.  
  179.  
  180. #endif  /* SGML_H */
  181.